home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
prolog
/
modprolg
/
mod-prol.lha
/
Prolog
/
modlib
/
src
/
$oldconsult.P
< prev
next >
Wrap
Text File
|
1992-06-01
|
5KB
|
134 lines
/************************************************************************
* *
* The SB-Prolog System *
* Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987 *
* *
************************************************************************/
/*-----------------------------------------------------------------
SB-Prolog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the SB-Prolog General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
SB-Prolog, but only under the conditions described in the
SB-Prolog General Public License. A copy of this license is
supposed to have been given to you along with SB-Prolog so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
------------------------------------------------------------------ */
/****************************************************************************
* *
* This file has been changed by to include Modules Extensions *
* Changes by : Brian Paxton 1991/92 *
* Last update : June 1992 *
* *
* Organisation : University of Edinburgh. *
* For : Departments of Computer Science and Artificial Intelligence *
* Fourth Year Project. *
* *
****************************************************************************/
/* $oldconsult.P */
/* $oldconsult(Filename) consults the named file for interpretation.
The second (optional) parameter to consult is a list of options.
A `v' means verbose. An `e' means expand macros. `t' means put trace
points on any untraced predicate in the file being consulted. `q'
means do a "quick" consult.
(Macros are clauses with ::-. They are evaluated, if possible,
at compile time. They MUST be PURE Horn clauses)
The third (optional) parameter is used to return a list of
predicate/arity pairs that were defined by the consult. This list
can be passed to trace/1 so that they can be traced.
Modified to assert all clauses into the root module.
*/
$oldconsult_export([$oldconsult/1,$oldconsult/2,$oldconsult/3,
$oldconsult_list/1]).
% $oldconsult_use : $blist, $bio, $assert, $getclauses, $bmeta, $mac
$oldconsult(File) :- $oldconsult(File,[e]).
$oldconsult(File,Opts) :- not(not($oldconsult(File,Opts,_))).
/* side-effects only*/
$oldconsult(File,Opts,Predlist) :-
$atomic(File) ->
($oldconsultable(File) ->
($getclauses(File,Clslist,Predlist),!,
$macexp(Clslist,Opts,Nclslist),
$oldconsult_s(File,Nclslist,Opts),
$symtype('_$traced_preds'(_),Tr),
(Tr > 0 -> $oldconsult_untrace(Predlist) ; true),
($memberchk(t,Opts) -> $oldconsult_trace(Predlist) ; true),
!
) ;
($print('** No such file: '), $print(File), $nl)
) ;
($print('** Illegal filename '), $print(File),
$print(' for oldconsult: filename must be atomic'), $nl
).
$oldconsultable(user).
$oldconsultable(File) :- exists(File).
$oldconsult_s(File,Clslist,Opts) :-
/* Clslist is list of terms: pred(Pred,Arity,_,_,ClauseList)
where Clauselist is a list of terms:
fact(Fact,CpyFlagRest) or rule(Head,Body,CpyFlag,CpyFlagRest) */
$member(pred(Pred,Arity,_,_,Clauselist),Clslist),
$bldstr(Pred,Arity,Call),$oldconsult_abolish(Call),
($member(v,Opts)->
$tab(15),$writename('including : '),$writename(Pred),
$writename('/'),$writename(Arity),$nl
;
true),
$oldconsult_islist(Clauselist),
$member(Factorrule,Clauselist),
$oldconsult_assert(Factorrule),
fail.
$oldconsult_s(_,_,_).
$oldconsult_islist([]) :- !.
$oldconsult_islist([_|Tail]) :- $oldconsult_islist(Tail).
$oldconsult_abolish(Goal) :- $buff_code(Goal,0,11,0).
$oldconsult_assert(fact(Fact,_)) :- $assert(Fact).
$oldconsult_assert(rule(Head,Body,_,_)) :- $assert((Head :- Body)).
$oldconsult_untrace([]).
$oldconsult_untrace(['/'(P,N)|Prest]) :-
('_$traced_preds'(P/N) ->
($retract('_$traced_preds'(P/N)), trace(P/N)) ;
true
),
$oldconsult_untrace(Prest).
$oldconsult_trace(L) :-
$symtype('_$traced_preds'(_),N),
(N > 0 -> $oldconsult_trace1(L) ; trace(L)).
$oldconsult_trace1([]).
$oldconsult_trace1([P|Prest]) :-
('_$traced_preds'(P) -> true ; trace(P)),
$oldconsult_trace1(Prest).
$oldconsult_list([]).
$oldconsult_list([H|T]) :- $oldconsult_list1(H), $oldconsult_list(T).
$oldconsult_list1('-'(File)) :- !, $oldconsult(File).
$oldconsult_list1(File) :- $oldconsult(File).
/* ------------------------------ $oldconsult.P ---------------------------- */